<?php

include "../controller/ConectBanco.php";

$idDevice = $_POST["idDevice"];

$result = mysql_query("SELECT DISTINCT idPosicao,latitude, longitude,velocidade,realDateTime,idDevice
						 FROM posicao
						WHERE idDevice = $idDevice
						ORDER BY realDateTime desc
						LIMIT 10")or die (mysql_error());
$i=0;
header("Content-Type: application/json");
$jsonData = '{';
while ($row = mysql_fetch_array($result)) {
	$i++;
	$jsonData .= '"posicao'.$i.'":{"idPosicao"  :'.$row["idPosicao"].',
			                       "latitude"   :"'.$row["latitude"].'",
			                       "longitude"  :"'.$row["longitude"].'",
			                       "velocidade" :"'.$row["velocidade"].'",
								   "dateTime"   :"'.$row["realDateTime"].'"},';
	
}
$jsonData = chop($jsonData,",");
$jsonData .= '}';

echo $jsonData;

?>